<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:pr="http://primefaces.prime.com.tr/ui"
      xmlns:f="http://java.sun.com/jsf/core">

    <ui:composition template="WEB-INF/facelets/template.xhtml">

        <ui:param name="title" value="View Cart"/>

        <ui:define name="content">
            <h1>This is cart.xhtml</h1>
            <pr:growl id="growl" showDetail="true"/>
            
            <h:form>
            <pr:commandButton rendered="#{cartModel.count > 0}" value="Order!" action="#{cartModel.placeOrder()}" ajax="false"/>
            </h:form>

            <h:form>
                <pr:dataTable var="product" value="#{cartModel.productsAlone}">
                    <pr:column sortBy="#{product.id}">
                        <f:facet name="header">
                            ID
                        </f:facet>
                        <h:outputText value="#{product.articleNumber}"/>
                    </pr:column>
                    <pr:column sortBy="#{product.name}">
                        <f:facet name="header">
                            Name
                        </f:facet>
                        <h:outputText value="#{product.name}"/>
                    </pr:column>
                    <pr:column sortBy="#{product.category.name}">
                        <f:facet name="header">
                            Category
                        </f:facet>
                        <h:outputText value="#{product.category.name}"/>
                    </pr:column>
                    <pr:column sortBy="#{product.price}">
                        <f:facet name="header">
                            Price
                        </f:facet>
                        <h:outputText value="#{product.price}"/>
                    </pr:column>
                    <pr:column sortBy="#{product.price}">
                        <f:facet name="header">
                            Quantity
                        </f:facet>
                        <h:outputText value="#{cartModel.getCount(product)}"/>
                    </pr:column>
                    <pr:column sortBy="#{productList.quantity}">
                        <f:facet name="header">
                            Qty
                        </f:facet>
                        <h:outputText value="#{productList.quantity}"/>
                    </pr:column>
                    <pr:column sortBy="#{productList.totalPrice}">
                        <f:facet name="header">
                            Total Price
                        </f:facet>
                        <h:outputText value="#{productList.totalPrice}"/>
                    </pr:column>
                    <pr:column>
                        <pr:commandButton value="Remove" action="#{cartModel.removeProductOne(product)}" update="@form"/>
                    </pr:column>
                </pr:dataTable>
            </h:form>

        </ui:define>
    </ui:composition>
</html>

